﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<QianBuo.Lottery.Web.Models.Account.DetailModel>" %>
<%@ Import Namespace="QianBuo.Lottery.Web.Models.Account" %>
<%@ Import Namespace="Code.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	账变明细
    <% TempData["Account_Report_Serch.Type"] = Model.Serch.Type; %>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div>
    <% Html.DisableClientValidation(); %>
    <% Html.BeginForm(Url.Route(new { Serc = new { Page = null as int? } }), Url.Route(new { id = "serchreportform" })); %>
    <table class="table" width="100%">
        <tr class="th"><th align="left" colspan="6">&nbsp;查找条件</th></tr>
        <tr>
            <td align="left">
                <label for="Serch_Type">类型:</label>
                <%=Html.DropDownListFor(p=>p.Serch.Type,Model.Types.OrderBy(p=>p.Text.Length).Each(p=>p.Selected=p.Value.Equals(Model.Serch.Type??(object)string.Empty))) %>
            </td>
            <td >
                <label for="Serch_MinTime">金额:</label>
                <input type="text" name="Serch.MinMoney" id="Serch_MinMoney" validate="{number:true,range:[0,999999999],messages:{number:'*',range:'*'}}" class="text80" value='<%=Model.Serch.MinMoney %>' />
            </td>
            <td >
                <label for="Serch_MaxMoney">至:</label>
                <input type="text" name="Serch.MinMoney" id="Serch_MaxMoney" validate="{number:true,range:[0,999999999],messages:{number:'*',range:'*'}}" class="text80" value='<%=Model.Serch.MaxMoney %>' />
            </td>
            <td >
                <label for="Serch_StartTime">时间:</label>
                <input type="text" name="Serch.StartTime" id="Serch_StartTime" onclick="WdatePicker()"
                    class="text80" value='<%=Model.Serch.StartTime.HasValue?Model.Serch.StartTime.Value.ToString("yyyy-MM-dd"):"" %>' />
            </td>
            <td >
                <label for="Serch_EndTime">至:</label>
                <input type="text" name="Serch.EndTime" id="Serch_EndTime" onclick="WdatePicker()"
                    class="text80" value='<%=Model.Serch.EndTime.HasValue?Model.Serch.EndTime.Value.ToString("yyyy-MM-dd"):"" %>' />
            </td>
            <td align="center"><input type="submit" value="查找" /></td>
        </tr>
    </table>
    <%=Html.HiddenFor(p=>p.PageSize) %>
    <% Html.EndForm(); %>
    
    <p />
    <% var flag = Model.Serch == null || Model.Serch.Type == null; %>
    <table id="report" class="table" width="100%">
        <tr class="th"><th width="15%">日期</th><th width="8%">类型</th><th width="10%">收入</th><th width="10%">支出</th>
        <%if(flag){ %>
        <th width="10%">返点</th>
        <% }%>
        <th width="35%">备注</th><th width="10%">余额</th></tr>
        <%  if (Model.Details != null)
            {
                var list = Model.Details.Where(p => p.Type != UserAccountDetailType.BackMoney || Model.Serch != null && Model.Serch.Type == UserAccountDetailType.BackMoney);
                if (list.Count() > 0)
                {
                    foreach (var item in list)
                    {
                        if (item.Type == UserAccountDetailType.TackMoney)
                            item.Memo = string.IsNullOrEmpty(item.Memo.Replace("&", "")) ? "" : item.Memo.Replace("&&", "管理员说:").Replace("&", "我    说:");%>
                <tr id="tritem" class='item_<%=((UserAccountDetailType)item.Type).ToString() %>'>
                <td ><%=string.Format("{0:yyyy-MM-dd HH:mm:ss}", item.AddTime)%></td>
                <td><%=((UserAccountDetailType)item.Type).GetName()%></td>
                <td align="right"><%=string.Format("{0:F}", item.InMoney ?? 0)%></td>
                <td align="right"><%=string.Format("{0:F}", item.OutMoney ?? 0)%></td>
                <%if (flag)
                  {
                      var temp = Model.Details.FirstOrDefault(p => p.ID == item.ID && p.Type == UserAccountDetailType.BackMoney);
                      %>
                <td align="right"><%=string.Format("{0:F}", item.Type != UserAccountDetailType.Play && item.Type != UserAccountDetailType.WinMoney ? 0 : temp == null ? 0 : temp.InMoney ?? 0)%></td>
                <%}%>
                <%
            item.Memo = (!string.IsNullOrEmpty(item.Memo) && !string.IsNullOrEmpty(item.StateText) ? item.Memo + "," + item.StateText : item.Memo + item.StateText) ?? "";
            var str = item.Memo.Length < 38 ? item.Memo : item.Memo.Substring(0, 35) + "...";
            str = string.IsNullOrEmpty(str) ? "详情" : str;
            var act = null as string;
            var menu = new { act = Request["act"] ?? "Detail", cont = Request["cont"] ?? "Account", arst = Request["arst"] ?? (Model.Serch.Type ?? (object)string.Empty).ToString() };
            var ReturnUrl = Url.Action("Detail", "Account", Url.Route(new { Model.Serch, Model.PageSize, Model.Page, ReturnUrl = Request["ReturnUrl"] }, menu));

            switch (item.Type)
            {
                case UserAccountDetailType.Play:
                case UserAccountDetailType.WinMoney:
                case UserAccountDetailType.WinMoney_Child:
                case UserAccountDetailType.QuashScheme:
                case UserAccountDetailType.BackMoney:
                case UserAccountDetailType.BackMoney_Child:
                    if (item.StateText == SchemeState.Normal.GetName())
                        act = Url.Action("Detail", "Scheme", Url.Route(new { SchemeID = item.ID.Replace("-", ""), ReturnUrl }, menu));
                    else
                        act = Url.Action("HistoryDetail", "Scheme", Url.Route(new { SchemeID = item.ID.Replace("-", ""), ReturnUrl }, menu));
                    break;
                case UserAccountDetailType.TackMoney:
                    act = Url.Action("TakeMoneyDetail", "User", Url.Route(new { id = item.ID, ReturnUrl }, menu));
                    break;
                case UserAccountDetailType.Other:
                    if (item.State == ((int)OtherMoneyDetailType.ChaseDetailCancle).ToString() && item.Info.ContainsKey("TaskID"))
                        act = act = Url.Action("Detail", "ChaseTask", Url.Route(new { ChaseID = item.Info["TaskID"].Replace("-", ""), DetailID = item.ID, ReturnUrl }, menu));
                    else if (item.State == ((int)OtherMoneyDetailType.ChaseTaskCancle).ToString())
                        act = act = Url.Action("Detail", "ChaseTask", Url.Route(new { ChaseID = item.ID.Replace("-", ""), ReturnUrl }, menu));
                    else if (item.State == ((int)OtherMoneyDetailType.BackTimeOutScheme).ToString())
                        act = act = Url.Action("HistoryDetail", "Scheme", Url.Route(new { SchemeID = item.ID.Replace("-", ""), ReturnUrl }, menu));
                    break;
                case UserAccountDetailType.ChaseTask:
                    act = act = Url.Action("Detail", "ChaseTask", Url.Route(new { ChaseID = item.ID.Replace("-", ""), ReturnUrl }, menu));
                    break;
            } %>
                <td align="left" tite='<%=item.Memo %>'>
                    <div class="winnumberitem width220">
                        <label title='<%=item.Memo %>'><a <%=act == null ? "" : "href='" + act + "' class='a_blue'" %>><%=str%></a></label>
                    </div>
                </td>
                <td><%=string.Format("{0:F2}", item.Money ?? 0)%></td>
              </tr>
              <% } %>
          <tr>
            <td><font color="red">合计</font></td>
              <td>&nbsp;</td>
              <td align="right">
                  <%=string.Format("{0:C}", Model.SumDetail.InMoney ?? 0)%>
              </td>
              <td align="right">
                  <%=string.Format("{0:C}", Model.SumDetail.OutMoney ?? 0)%>
              </td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <%if (flag){%>
              <td>&nbsp;</td>
              <%} %>
          </tr>
          <tr>
            <td colspan="<%=flag?"7":"6" %>"><%=Html.Pager(Model.Page.Value, Model.PageSize, Model.SumCount, "Page", Url.Route(new { Model.Serch, Model.PageSize, ReturnUrl = Request["ReturnUrl"], act = Request["act"], cont = Request["cont"], arst = Request["arst"] }), "PageSize")%></td>
          </tr>
          <%}
            else
            {%>
                <tr><td colspan="<%=flag?"7":"6" %>">无记录！</td></tr>
            <%}
            }
            else
            {%>
                <tr><td colspan="<%=flag?"7":"6" %>">无记录！</td></tr>
            <%} %>
    </table>
    <%if (Request["ReturnUrl"] != null)
      {%>
      <a class="a_blue" href='<%=Request["ReturnUrl"] %>'>&gt;&gt;返回</a>
    <%} %>
</div>


</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="StyleAndScript" runat="server">
    <script src='<%=Url.Content("~/Scripts/jquery.metadata.js") %>' type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#serchreportform").validate();
            $("#report #tritem:odd").addClass("supersede");
        });
    </script>
</asp:Content>
